package com.lgk.mapper;

import com.lgk.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface URMapper {
    //获取用户全部角色
    @Select("select * from user where name like concat('%',#{name},'%')")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "password", property = "password"),
            @Result(column = "tell", property = "tell"),
            @Result(column = "time", property = "time"),
            @Result(
                    property = "roleList",
                    column = "id",
                    javaType = List.class,
                    many = @Many(select = "com.lgk.mapper.RoleMapper.getByUId")
            )
    })
    List<User> getAllUR(String name);

    //根据id获取用户全部角色
    @Select("select * from user where id = #{id}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "password", property = "password"),
            @Result(column = "tell", property = "tell"),
            @Result(column = "time", property = "time"),
            @Result(
                    property = "roleList",
                    column = "id",
                    javaType = List.class,
                    many = @Many(select = "com.lgk.mapper.RoleMapper.getByUId")
            )
    })
    User getById(Integer id);


  /*  //获取某个用户的全部角色
    @Select("select * from user where name like concat('%',#{userName},'%')")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "password", property = "password"),
            @Result(column = "tell", property = "tell"),
            @Result(column = "time", property = "time"),
            @Result(
                    property = "roleList",
                    column = "id",
                    javaType = List.class,
                    many = @Many(select = "com.lgk.mapper.RoleMapper.getByUId")
            )
    })
    List<User> getByUserNameAllUR(String userName);*/

/*    //按角色名称模糊查询
    @Select("select * from user u, ur ur where u.name like " +
            "concat('%',#{roleName},'%') and u.id = ur.uId")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "password", property = "password"),
            @Result(column = "tell", property = "tell"),
            @Result(column = "time", property = "time"),
            @Result(
                    property = "userList",
                    column = "id",
                    javaType = List.class,
                    many = @Many(select = "com.lgk.mapper.RoleMapper.getByUId")
            )
    })
    List<User> getByRoleNameAllUR(String roleName);

    //按用户名、角色名模糊查询
    @Select("select *from user u, ur ur, role r where u.name like concat('%',#{userName},'%')" +
            "and r.name like concat('%',#{roleName},'%') and" +
            "u.id = ur.uId and r.id = ur.rId")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "password", property = "password"),
            @Result(column = "tell", property = "tell"),
            @Result(column = "time", property = "time"),
            @Result(
                    property = "userList",
                    column = "id",
                    javaType = List.class,
                    many = @Many(select = "com.lgk.mapper.RoleMapper.getByUId")
            )
    })
    List<User> getByNameAllUR(String userName, String roleName);*/
}
